package co.edu.unal.satacredito.rest.repositories.general;

import java.io.Serializable;
import java.util.Date;

import javax.ejb.Stateless;

import co.edu.unal.satacredito.rest.domain.general.CardType;
import co.edu.unal.satacredito.rest.domain.general.GenericTransaction;
import co.edu.unal.satacredito.rest.domain.general.ValidationResult;
import co.edu.unal.satacredito.rest.domain.visa.ValidationStatus;

/**
 * Session Bean implementation class ValidateGenericTransaction
 */
@Stateless
public class ValidateGenericTransaction implements
		ValidateGenericTransactionRemote, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Default constructor.
	 */
	public ValidateGenericTransaction() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public GenericTransaction validate(GenericTransaction genericTransaction) {

		
		genericTransaction.setValidationDate(new Date());
		
		// first check the document

		boolean validDocument = true;

		if (!validDocument) {
			
			genericTransaction.setValidationMessage("El documento de identidad es invalido");
			genericTransaction.setValidationResult(ValidationResult.INVALID_DOCUMENT);
			
			return genericTransaction;
		} else {

			// then check the transaction
			boolean validCard = false;
			if (genericTransaction.getCardType().equals(CardType.CREDIT)) {
				validCard = validateCreditCard(genericTransaction);
			} else {
				validCard = validateDebitCard(genericTransaction);
			}
			
			genericTransaction.setValidationMessage("La tarjeta es invalida");
			genericTransaction.setValidationResult(ValidationResult.INVALID_DOCUMENT);
			
			return genericTransaction;
		}

	}

	private boolean validateDebitCard(GenericTransaction genericTransaction) {
		return false;
	}

	private boolean validateCreditCard(GenericTransaction genericTransaction) {
		return false;
	}

}
